home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / kms20src.lha / KMSC / filebase.c < prev    next >
C/C++ Source or Header  |  1995-04-04  |  40KB  |  1,441 lines

  1. /**********************************
  2.  *              KMS               *
  3.  **********************************
  4.  *  ©1992 by BlackMagic Software  *
  5.  **********************************
  6.  *                                *
  7.  **********************************/
  8.  
  9. #include <KMS/KMS.h>
  10. #include <KMS/KMS_devlib.h>
  11.  
  12. Prototype VOID Upload(UBYTE);
  13. Prototype VOID Download(UMSMsgNum, UBYTE, STRPTR);
  14. Prototype VOID XPRReceive(VOID);
  15. Prototype BOOL XPRSend(VOID);
  16. Prototype BOOL MoveBin(UMSMsgNum, struct AreaNode *, BOOL);
  17. Prototype struct Window *GetWindow(VOID);
  18. Prototype UBYTE ProtSelect(BOOL);
  19. Prototype VOID DeleteBinary(UMSMsgNum, struct AreaNode *);
  20. Prototype VOID BatchUpload(VOID);
  21. Prototype VOID MsgUpload(VOID);
  22. Prototype BOOL LocalDownload(VOID);
  23.  
  24. extern VOID KPrintF(APTR, ...);
  25.  
  26. /*****************************
  27.  * Externe Globale Variablen *
  28.  *****************************/
  29.  
  30. extern struct KMSBase *KMSBase;
  31. extern struct LocalConfig *KMS_LC;
  32.  
  33. extern STRPTR PPArg, PPArg2, PPArg3;
  34.  
  35. extern UBYTE ShutDown, Plop;
  36.  
  37. extern UMSAccount MyUMSAccount, SysUMSAccount;
  38. extern UMSMsgNum Lastmsg;
  39.  
  40. extern struct TagItem UMSReadTags[];
  41. extern struct TagItem UMSListTags[];
  42. extern struct MessageInfo RMsgInfo;
  43. extern STRPTR RAttributes;
  44. extern STRPTR RGroup;
  45. extern STRPTR RSubject;
  46.  
  47. extern TEXT KMSTempDat[];
  48.  
  49. /*********************
  50.  * Globale Variablen *
  51.  *********************/
  52.  
  53. struct Library *AslBase;
  54. static struct FileRequester *FileRequester;
  55.  
  56. TEXT BinaryName[LEN_DOSPATH+1];
  57. ULONG BinarySize;
  58.  
  59. /********************************
  60.  * Upload                       *
  61.  ********************************
  62.  * I: flag                      *
  63.  * O: ---                       *
  64.  ********************************/
  65.  
  66. /// "Upload"
  67.  
  68. VOID Upload(UBYTE flag)
  69.    {
  70.    struct Window *mywin;
  71.    TEXT frompath[LEN_DOSPATH+1];
  72.    TEXT topath[LEN_DOSPATH+1];
  73.    TEXT sizebuff[LEN_NUMBER+1];
  74.    BOOL success = FALSE;
  75.    struct AreaNode *current = KMS_LC->Session.CurrentArea;
  76.    ULONG filesize;
  77.    STRPTR fromfile, filename;
  78.  
  79.    if (!flag)
  80.       {
  81.       /* Zugriff prüfen */
  82.  
  83.       if (!(current->AreaData.Type & (ATYPE_FILES|ATYPE_PRIVATE)))
  84.          {
  85.          SysMsg(NO_FILE_AREA);
  86.          return;
  87.          }
  88.  
  89.       if (!(CheckAccess(current) & AACC_WRITE))
  90.          {
  91.          PPArg = KMS_LC->Session.InputBuffer;
  92.          SysMsg(NO_WRITE_ACCESS);
  93.          PPArg = NULL;
  94.          return;
  95.          }
  96.       }
  97.  
  98.    /* File besorgen */
  99.  
  100.    if (KMS_LC->Device & DEV_CONSOLE)
  101.       {
  102.       /* Lokaler File-Requester, empfangene Dateien nach KMSBase->TempDir */
  103.  
  104.       if (mywin = GetWindow())
  105.          {
  106.          if (AslBase = OpenLibrary(AslName, 36))
  107.             {
  108.             if (FileRequester = AllocAslRequestTags(ASL_FileRequest, ASL_Hail, "Select files to upload...",
  109.                                                                     ASL_Window, mywin,
  110.                                                                     ASL_FuncFlags, FILF_MULTISELECT,
  111.                                                                     TAG_DONE))
  112.                {
  113.                if (AslRequest(FileRequester, NULL))
  114.                   {
  115.                   LONG numfiles = FileRequester->rf_NumArgs;
  116.                   struct WBArg *filelist = FileRequester->rf_ArgList;
  117.  
  118.                   if (!numfiles || !filelist)
  119.                      success = TRUE; /* Damit unten keine Fehlermeldung */
  120.  
  121.                   while(filelist && numfiles)
  122.                      {
  123.                      *frompath = '\0';
  124.                      success = FALSE;
  125.  
  126.                      strcpy(frompath, FileRequester->rf_Dir);
  127.                      AddPart(frompath, filelist->wa_Name, sizeof(frompath));
  128.                      fromfile = filelist->wa_Name;
  129.  
  130.                      if (*frompath)
  131.                         {
  132.                         /* Datei nach TempDir kopieren */
  133.  
  134.                         sprintf(topath, "%s%s", KMSBase->TempDir, fromfile);
  135.                         if (Copy(frompath, topath, FALSE))
  136.                            success = TRUE;
  137.                         }
  138.                      
  139.                      if (filelist)
  140.                         filelist++;
  141.                      numfiles--;
  142.  
  143.                      if (!success || (flag & UL_MSG))
  144.                         numfiles = 0;
  145.                      }
  146.                   }
  147.                else
  148.                   success = TRUE; /* Damit unten keine Fehlermeldung */
  149.  
  150.                FreeFileRequest(FileRequester);
  151.                }
  152.  
  153.             CloseLibrary(AslBase);
  154.             }
  155.          }
  156.  
  157.       if (!success)
  158.          SystemError("Upload", "Local");
  159.       }
  160.    else
  161.       {
  162.       /* Remote Dateitransfer, empfangene Dateien nach KMSBase->TempDir */
  163.  
  164.       XPRReceive();
  165.       }
  166.  
  167.    /* Dateinamen aus KMSBase->TempDir einlesen und abarbeiten */
  168.  
  169.    LONG more;
  170.    BPTR mylock;
  171.    struct ExAllData *eadata, *ead;
  172.  
  173.    eadata = (struct ExAllData *)AllocMem(LEN_EADATA, MEMF_CLEAR);
  174.    if (!eadata)
  175.       {
  176.       SystemError("Upload", "AllocMem");
  177.       return;
  178.       }
  179.    if (!(mylock = Lock(KMSBase->TempDir, SHARED_LOCK)))
  180.       {
  181.       FreeMem(eadata, LEN_EADATA);
  182.  
  183.       SystemError("Upload", "Lock");
  184.       return;
  185.       }
  186.    struct ExAllControl *eac = AllocDosObject(DOS_EXALLCONTROL, NULL);
  187.    if (!eac)
  188.       {
  189.       UnLock(mylock);
  190.       FreeMem(eadata, LEN_EADATA);
  191.  
  192.       SystemError("Upload", "AllocDosObject");
  193.       return;
  194.       }
  195.    eac->eac_LastKey = 0;
  196.    eac->eac_MatchString = NULL;
  197.    eac->eac_MatchFunc = NULL;
  198.  
  199.    do {
  200.       more = ExAll(mylock, eadata, LEN_EADATA, ED_SIZE, eac);
  201.       /* If non-zero is returned, you MUST call ExAll again until
  202.          it returns FALSE. */
  203.  
  204.       if (more == DOSFALSE && IoErr() != ERROR_NO_MORE_ENTRIES)
  205.          break;
  206.       else if (eac->eac_Entries == 0)
  207.          continue;
  208.  
  209.       ead = eadata;
  210.       do {
  211.          filename = ead->ed_Name;
  212.          filesize = ead->ed_Size;
  213.          strcpy(frompath, KMSBase->TempDir);
  214.          strcat(frompath, filename);
  215.          sprintf(sizebuff, "%ld", filesize);
  216.          ConvertSpace(filename);
  217.          PPArg = filename;
  218.          PPArg2 = sizebuff;
  219.          SysMsg(UPLOAD_WORKING);
  220.          PPArg = NULL;
  221.          PPArg2 = NULL;
  222.  
  223.          if (filesize)
  224.             {
  225.             if (flag & UL_PRIV)
  226.                {
  227.                strcpy(topath, KMSBase->UserDir);
  228.                strcat(topath, KMS_LC->Session.CurrentUser->UserData.Name);
  229.                ConvertSpace(topath);
  230.  
  231.                LONG quota = DirWork(topath, "~(#?.KMS)", 0);
  232.                quota = KMS_LC->Session.CurrentUser->UserData.Quota * 1024L - quota - filesize;
  233.                if (quota < 0)
  234.                   SysMsg(QUOTA_EXCEEDED);
  235.                else
  236.                   {
  237.                   strcat(topath, "/");
  238.                   strcat(topath, filename);
  239.  
  240.                   if (Exists(topath))
  241.                      SysMsg(BINARY_EXISTS);
  242.                   else
  243.                      {
  244.                      /* Datei umsetzen von frompath nach topath */
  245.  
  246.                      if (!Copy(frompath, topath, FALSE))
  247.                         SystemError("Upload", "Move");
  248.                      else
  249.                         SysMsg(UPLOAD_SUCCESSFUL);
  250.                      }
  251.                   }
  252.                }
  253.             else if (flag & UL_MSG)
  254.                {
  255.                /* Datei umsetzen von frompath nach KMSTempDat */
  256.  
  257.                if (!Copy(frompath, KMSTempDat, FALSE))
  258.                   SystemError("Upload", "Move");
  259.                else
  260.                   SysMsg(UPLOAD_SUCCESSFUL);
  261.                }
  262.             else
  263.                {
  264.                strcpy(topath, current->AreaData.FilePath);
  265.                if (topath[strlen(topath)-1] != ':' && topath[strlen(topath)-1] != '/')
  266.                   strcat(topath, "/");
  267.                strcat(topath, filename);
  268.  
  269.                if (Exists(topath))
  270.                   SysMsg(BINARY_EXISTS);
  271.                else
  272.                   {
  273.                   /* Beschreibung besorgen */
  274.  
  275.                   strcpy(BinaryName, filename);
  276.                   BinarySize = filesize;
  277.  
  278.                   if (WriteMsg(WF_NEW|WF_BINARY, NULL, NULL, NULL))
  279.                      {
  280.                      /* Datei umsetzen von frompath nach topath */
  281.  
  282.                      if (!Copy(frompath, topath, FALSE))
  283.                         SystemError("Upload", "Move");
  284.                      }
  285.                   }
  286.                }
  287.             }
  288.  
  289.          DeleteFile(frompath);
  290.  
  291.          ead = ead->ed_Next;
  292.          } while(ead);
  293.  
  294.       } while(more == DOSTRUE);
  295.  
  296.    FreeDosObject(DOS_EXALLCONTROL, eac);
  297.    UnLock(mylock);
  298.    FreeMem(eadata, LEN_EADATA);
  299.    }
  300.  
  301. ///
  302.  
  303. /********************************
  304.  * Download                     *
  305.  ********************************
  306.  * I: Msg-Nr., Flag, Dateiname  *
  307.  * O: ---                       *
  308.  ********************************/
  309.  
  310. /// "Download"
  311.  
  312. /* DOWN_XFER     \  DOWN_PRIVATE
  313.    DOWN_LIST      \ DOWN_CURRENT
  314.    DOWN_SELECT    / DOWN_SELECTED
  315.    DOWN_DESELECT /  DOWN_RANGE    */
  316.  
  317. VOID Download(UMSMsgNum num, UBYTE flag, STRPTR privname)
  318.    {
  319.    TEXT frompath[LEN_DOSPATH+1];
  320.    struct AreaNode *current = KMS_LC->Session.CurrentArea;
  321.    STRPTR arg;
  322.    STRPTR rsubject = "";
  323.    TEXT fname[LEN_DOSFILE+1];
  324.    TEXT fsizebuff[LEN_NUMBER+1];
  325.    TEXT buff[LEN_MAXLINE+1];
  326.    ULONG fsize, sumsize;
  327.    UWORD avgsecs, avgmin;
  328.    FILE *logfile;
  329.    BOOL titel = TRUE;
  330.  
  331.    /* UMSUSTATF_PostPoned: Markierte Binärfiles */
  332.  
  333.    if (flag & (DOWN_CURRENT|DOWN_RANGE))
  334.       {
  335.       /* Zugriff prüfen */
  336.  
  337.       if (!(current->AreaData.Type & (ATYPE_FILES|ATYPE_PRIVATE)))
  338.          {
  339.          SysMsg(NO_FILE_AREA);
  340.          return;
  341.          }
  342.  
  343.       if (!(KMS_LC->Session.CurrentAccess & AACC_READ))
  344.          {
  345.          PPArg = KMS_LC->Session.InputBuffer;
  346.          SysMsg(NO_READ_ACCESS);
  347.          PPArg = NULL;
  348.          return;
  349.          }
  350.  
  351.       SelectArea(KMS_LC->Session.CurrentArea->AreaData.MBName);
  352.  
  353.       if (!(flag & DOWN_RANGE))
  354.          {
  355.          if (!num && !(num = Lastmsg))
  356.             {
  357.             SysMsg(NO_MSG_READ);
  358.             return;
  359.             }
  360.  
  361.          /* Nachricht vorhanden? */
  362.  
  363.          UMSReadTags[0].ti_Data = num;
  364.  
  365.          if (!ReadUMSMsg(MyUMSAccount, &UMSReadTags[0])
  366.             || !(RMsgInfo.msgi_LoginStatus & KMSLSTATF_Visible))
  367.             {
  368.             SysMsg(MSG_NOT_FOUND);
  369.             FreeUMSMsg(MyUMSAccount, num);
  370.             return;
  371.             }
  372.  
  373.          /* Msg in aktueller Gruppe? */
  374.  
  375.          if (!(RMsgInfo.msgi_LoginStatus & KMSLSTATF_InGroup))
  376.             {
  377.             SysMsg(MSG_NOT_IN_AREA);
  378.             FreeUMSMsg(MyUMSAccount, num);
  379.             return;
  380.             }
  381.  
  382.          /* Binärfile? */
  383.  
  384.          fsize = 0;
  385.          *fname = '\0';
  386.          *fsizebuff = '\0';
  387.          if (RAttributes)
  388.             {
  389.             /* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
  390.  
  391.             if (arg = strstr(RAttributes, "KMS_FNAME:"))
  392.                {
  393.                sscanf(arg, "KMS_FNAME:%30s", fname);
  394.  
  395.                if (arg = strstr(RAttributes, "KMS_FSIZE:"))
  396.                   sscanf(arg, "KMS_FSIZE:%d", &fsize);
  397.                }
  398.             }
  399.  
  400.          /* Fileinfo aufbereiten */
  401.  
  402.          strcpy(frompath, current->AreaData.FilePath);
  403.          if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
  404.             strcat(frompath, "/");
  405.          strcat(frompath, fname);
  406.          if (!Exists(frompath))
  407.             fsize = 0;
  408.  
  409.          if (!fsize)
  410.             strcpy(fsizebuff, "????");
  411.          else if (fsize < 10000)
  412.             sprintf(fsizebuff, "%4d", fsize);
  413.          else
  414.             {
  415.             fsize /= 1024;
  416.             if (fsize < 1000)
  417.                sprintf(fsizebuff, "%3dK", fsize);
  418.             else
  419.                {
  420.                fsize /= 1024;
  421.                sprintf(fsizebuff, "%3dM", fsize);
  422.                }
  423.             }
  424.  
  425.          sprintf(buff, "%5ld  %s %-20.20s ", num, fsizebuff, fname);
  426.          if (strlen(buff) < KMS_LC->Session.CurrentUser->UserData.LineLen)
  427.             {
  428.             if (RSubject)
  429.                rsubject = RSubject;
  430.             strncat(buff, rsubject, KMS_LC->Session.CurrentUser->UserData.LineLen - strlen(buff));
  431.             buff[KMS_LC->Session.CurrentUser->UserData.LineLen] = '\0';
  432.             }
  433.          strcat(buff, "\n");
  434.  
  435.          FreeUMSMsg(MyUMSAccount, num);
  436.  
  437.          if (!fsize)
  438.             {
  439.             SysMsg(NO_BINARY_ATTACHED);
  440.             return;
  441.             }
  442.          }
  443.       }
  444.  
  445.    if ((flag & DOWN_XFER) && (flag & (DOWN_CURRENT|DOWN_PRIVATE)))
  446.       {
  447.       if (flag & DOWN_CURRENT)
  448.          {
  449.          /* Fileinfo ausgeben */
  450.  
  451.          SysMsg(SELBIN_HEAD);
  452.          MsgPrint(buff, 0);
  453.          Print(NULL, PF_NOBRK);
  454.          }
  455.       else
  456.          {
  457.          sprintf(frompath, "%s%s/%s",
  458.                           KMSBase->UserDir,
  459.                           KMS_LC->Session.CurrentUser->UserData.Name,
  460.                           privname);
  461.          ConvertSpace(frompath);
  462.  
  463.          if (!Exists(frompath))
  464.             {
  465.             SysMsg(FILE_NOT_FOUND);
  466.             return;
  467.             }
  468.          else
  469.             {
  470.             strcpy(fname, privname);
  471.  
  472.             PPArg = fname;
  473.             SysMsg(DOWNLOAD_PRIV);
  474.             PPArg = NULL;
  475.             }
  476.          }
  477.  
  478.       /* Dateipfad in "T:FILES.KMS" schreiben und Transfer starten */
  479.  
  480.       logfile = fopen("T:FILES.KMS", "w");
  481.       if (logfile)
  482.          {
  483.          BOOL success;
  484.  
  485.          fprintf(logfile, "%s\n", frompath);
  486.          fclose(logfile);
  487.  
  488.          if (KMS_LC->Device & DEV_SERIAL)
  489.             success = XPRSend();
  490.          else
  491.             success = LocalDownload();
  492.  
  493.          DeleteFile("T:FILES.KMS");
  494.  
  495.          if (success)
  496.             {
  497.             /* Als gelesen markieren */
  498.  
  499.             UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg,        num,
  500.                                         UMSTAG_SelSet,        UMSUSTATF_Old,
  501.                                         TAG_DONE);
  502.             UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg,        num,
  503.                                         UMSTAG_SelWriteLocal, TRUE,
  504.                                         UMSTAG_SelUnset,      KMSLSTATF_Unread,
  505.                                         TAG_DONE);
  506.             }
  507.          }
  508.       else
  509.          SystemError("Download", "Logwrite");
  510.       }
  511.    else if ((flag & (DOWN_XFER|DOWN_LIST)) && (flag & (DOWN_RANGE|DOWN_SELECTED)))
  512.       {
  513.       /* Download/Liste aller selektierten Binärfiles oder Nummern-Bereich */
  514.  
  515.       ULONG umsflag;
  516.       ULONG umslocal;
  517.  
  518.       if (flag & DOWN_SELECTED)
  519.          {
  520.          umsflag = UMSUSTATF_PostPoned;
  521.          umslocal = TAG_IGNORE;
  522.          }
  523.       else
  524.          {
  525.          umsflag = KMSLSTATF_InRange;
  526.          umslocal = UMSTAG_SearchLocal;
  527.          }
  528.  
  529.       sumsize = 0;
  530.  
  531.       num = 0;
  532.       while(num = UMSSearchTags(MyUMSAccount, UMSTAG_SearchLast, num,
  533.                                               UMSTAG_SearchDirection, 1,
  534.                                               umslocal, TRUE,
  535.                                               UMSTAG_SearchMask,  umsflag,
  536.                                               UMSTAG_SearchMatch, umsflag,
  537.                                               TAG_DONE))
  538.          {
  539.          UMSReadTags[0].ti_Data = num;
  540.  
  541.          /* Nächste passende Msg einlesen */
  542.          /* Weiter nur, wenn Nachricht sichtbar und KMS-Gruppe existiert */
  543.  
  544.          if (ReadUMSMsg(MyUMSAccount, &UMSReadTags[0])
  545.             && (RMsgInfo.msgi_LoginStatus & KMSLSTATF_Visible) && (current = AreaSearch(RGroup)))
  546.             {
  547.             if (titel)
  548.                {
  549.                if (flag & DOWN_SELECTED)
  550.                   SysMsg(SELBIN_HEAD);
  551.                else
  552.                   SysMsg(RANGEBIN_HEAD);
  553.                titel = FALSE;
  554.                }
  555.  
  556.             strcpy(frompath, current->AreaData.FilePath);
  557.             if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
  558.                strcat(frompath, "/");
  559.  
  560.             /* File-Info extrahieren */
  561.  
  562.             fsize = 0;
  563.             *fname = '\0';
  564.             *fsizebuff = '\0';
  565.             if (RAttributes)
  566.                {
  567.                /* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
  568.  
  569.                if (arg = strstr(RAttributes, "KMS_FNAME:"))
  570.                   {
  571.                   sscanf(arg, "KMS_FNAME:%30s", fname);
  572.  
  573.                   if (arg = strstr(RAttributes, "KMS_FSIZE:"))
  574.                      sscanf(arg, "KMS_FSIZE:%d", &fsize);
  575.                   }
  576.                }
  577.  
  578.             /* Fileinfo aufbereiten */
  579.  
  580.             strcat(frompath, fname);
  581.             if (!Exists(frompath))
  582.                fsize = 0;
  583.  
  584.             sumsize += fsize;
  585.  
  586.             if (!fsize)
  587.                strcpy(fsizebuff, "????");
  588.             else if (fsize < 10000)
  589.                sprintf(fsizebuff, "%4d", fsize);
  590.             else
  591.                {
  592.                fsize /= 1024;
  593.                if (fsize < 1000)
  594.                   sprintf(fsizebuff, "%3dK", fsize);
  595.                else
  596.                   {
  597.                   fsize /= 1024;
  598.                   sprintf(fsizebuff, "%3dM", fsize);
  599.                   }
  600.                }
  601.  
  602.             sprintf(buff, "%5ld  %s %-20.20s ", num, fsizebuff, fname);
  603.             if (strlen(buff) < KMS_LC->Session.CurrentUser->UserData.LineLen)
  604.                {
  605.                if (RSubject)
  606.                   rsubject = RSubject;
  607.                strncat(buff, rsubject, KMS_LC->Session.CurrentUser->UserData.LineLen - strlen(buff));
  608.                buff[KMS_LC->Session.CurrentUser->UserData.LineLen] = '\0';
  609.                }
  610.             strcat(buff, "\n");
  611.  
  612.             /* Fileinfo ausgeben */
  613.  
  614.             MsgPrint(buff, 0);
  615.  
  616.             /* Zum Empfang vorbereiten */
  617.  
  618.             if ((flag & DOWN_XFER) && fsize) /* Wenn nicht nur Liste und vorhanden */
  619.                {
  620.                /* Dateipfad und Name in "T:FILES.KMS" schreiben */
  621.  
  622.                logfile = fopen("T:FILES.KMS", "a");
  623.                if (logfile)
  624.                   {
  625.                   fprintf(logfile, "%s\n", frompath);
  626.                   fclose(logfile);
  627.                   }
  628.                else
  629.                   SystemError("Download", "Logwrite");
  630.                }
  631.  
  632.             FreeUMSMsg(MyUMSAccount, num);
  633.             }
  634.          }
  635.  
  636.       if (titel)
  637.          {
  638.          if (flag & DOWN_SELECTED)
  639.             SysMsg(NO_BINARY_SELECTED);
  640.          else
  641.             SysMsg(NO_BINARY_INRANGE);
  642.          }
  643.       else
  644.          {
  645.          /* Summary ausgeben */
  646.  
  647.          sprintf(fsizebuff, "%ld", sumsize);
  648.          PPArg = fsizebuff;
  649.          SysMsg(TOTAL_BYTES);
  650.          PPArg = NULL;
  651.  
  652.          if (KMS_LC->Device & DEV_SERIAL)
  653.             {
  654.             avgsecs = 0;
  655.             avgmin = 0;
  656.  
  657.             if (KMS_LC->Session.LineSpeed)
  658.                avgsecs = sumsize * 8 / KMS_LC->Session.LineSpeed;
  659.             avgmin = avgsecs / 60;
  660.             avgsecs = avgsecs % 60;
  661.  
  662.             if (KMS_LC->Session.LineSpeed)
  663.                sprintf(fsizebuff, "%02d:%02d", avgmin, avgsecs);
  664.             else
  665.                sprintf(fsizebuff, "??:??");
  666.  
  667.             PPArg = fsizebuff;
  668.             SysMsg(ESTIMATED_TIME);
  669.             PPArg = NULL;
  670.             }
  671.  
  672.          if (Exists("T:FILES.KMS"))
  673.             {
  674.             BOOL success;
  675.  
  676.             /* Transfer starten */
  677.  
  678.             if (KMS_LC->Device & DEV_SERIAL)
  679.                success = XPRSend();
  680.             else
  681.                success = LocalDownload();
  682.  
  683.             if (success)
  684.                {
  685.                /* Alle deselektieren und als gelesen markieren */
  686.  
  687.                if (flag & DOWN_SELECTED)
  688.                   {
  689.                   UMSSelectTags(MyUMSAccount, UMSTAG_SelMask,       UMSUSTATF_PostPoned,
  690.                                               UMSTAG_SelMatch,      UMSUSTATF_PostPoned,
  691.                                               UMSTAG_SelWriteLocal, TRUE,
  692.                                               UMSTAG_SelUnset,      KMSLSTATF_Unread,
  693.                                               TAG_DONE);
  694.                   UMSSelectTags(MyUMSAccount, UMSTAG_SelMask,  UMSUSTATF_PostPoned,
  695.                                               UMSTAG_SelMatch, UMSUSTATF_PostPoned,
  696.                                               UMSTAG_SelUnset, UMSUSTATF_PostPoned,
  697.                                               UMSTAG_SelSet,   UMSUSTATF_Old,
  698.                                               TAG_DONE);
  699.                   }
  700.                else
  701.                   {
  702.                   UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal, TRUE,
  703.                                               UMSTAG_SelMask,      KMSLSTATF_InRange,
  704.                                               UMSTAG_SelMatch,     KMSLSTATF_InRange,
  705.                                               UMSTAG_SelSet,       UMSUSTATF_Old,
  706.                                               TAG_DONE);
  707.                   UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal,  TRUE,
  708.                                               UMSTAG_SelWriteLocal, TRUE,
  709.                                               UMSTAG_SelMask,       KMSLSTATF_InRange,
  710.                                               UMSTAG_SelMatch,      KMSLSTATF_InRange,
  711.                                               UMSTAG_SelUnset,      KMSLSTATF_InRange | KMSLSTATF_Unread,
  712.                                               TAG_DONE);
  713.                   }
  714.                }
  715.             }
  716.  
  717.          DeleteFile("T:FILES.KMS");
  718.          }
  719.       }
  720.    else if (flag & DOWN_SELECT)
  721.       {
  722.       /* Selektieren */
  723.  
  724.       if (flag & DOWN_RANGE)
  725.          num = UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal, TRUE,
  726.                                            UMSTAG_SelMask,  KMSLSTATF_InRange,
  727.                                            UMSTAG_SelMatch, KMSLSTATF_InRange,
  728.                                            UMSTAG_SelSet,   UMSUSTATF_PostPoned,
  729.                                            TAG_DONE);
  730.       else
  731.          num = UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg, num,
  732.                                            UMSTAG_SelSet, UMSUSTATF_PostPoned,
  733.                                            TAG_DONE);
  734.  
  735.       sprintf(buff, "%ld", num);
  736.       PPArg = buff;
  737.       SysMsg(BINARY_SELECTED);
  738.       PPArg = NULL;
  739.       }
  740.    else if (flag & DOWN_DESELECT)
  741.       {
  742.       /* Deselektieren */
  743.  
  744.       if (flag & DOWN_RANGE)
  745.          num = UMSSelectTags(MyUMSAccount, UMSTAG_SelReadLocal, TRUE,
  746.                                            UMSTAG_SelMask,  KMSLSTATF_InRange,
  747.                                            UMSTAG_SelMatch, KMSLSTATF_InRange,
  748.                                            UMSTAG_SelUnset, UMSUSTATF_PostPoned,
  749.                                            TAG_DONE);
  750.       else
  751.          num = UMSSelectTags(MyUMSAccount, UMSTAG_SelMsg, num,
  752.                                            UMSTAG_SelUnset, UMSUSTATF_PostPoned,
  753.                                            TAG_DONE);
  754.  
  755.       sprintf(buff, "%ld", num);
  756.       PPArg = buff;
  757.       SysMsg(BINARY_DESELECTED);
  758.       PPArg = NULL;
  759.       }
  760.    }
  761.  
  762. ///
  763.  
  764. /********************************
  765.  * XPRReceive                   *
  766.  ********************************
  767.  * I: ---                       *
  768.  * O: ---                       *
  769.  ********************************/
  770.  
  771. /// "XPRReceive"
  772.  
  773. VOID XPRReceive(VOID)
  774.    {
  775.    TEXT name[LEN_DOSFILE+1];
  776.    TEXT cmdline[LEN_MAXLINE+1];
  777.    TEXT cfgstring[20];
  778.    UBYTE prot;
  779.    ULONG result;
  780.    STRPTR des, lib, opt, cmd;
  781.  
  782.    prot = ProtSelect(TRUE);
  783.    if (!prot)
  784.       return; /* User-Abbruch */
  785.  
  786.    sprintf(cfgstring, "KMS.xprdescrip%d", prot);
  787.    des = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  788.    sprintf(cfgstring, "KMS.xprlibrary%d", prot);
  789.    lib = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  790.    sprintf(cfgstring, "KMS.xproptions%d", prot);
  791.    opt = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  792.    strcpy(cfgstring, "KMS.xprcmdreceive");
  793.    cmd = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  794.  
  795.    if (!des || !lib || !opt || !cmd)
  796.       SystemError("XPRReceive", "Prot-Config");
  797.    else
  798.       {
  799.       /* Wenn nötig, Dateinamen anfordern */
  800.  
  801.       if (des[strlen(des)-1] != '@')
  802.          {
  803.          result = CmdInput(NULL, PROMPT_FILENAME, " /:,*?#~[]()!\"\\", NULL, LEN_DOSFILE, INF_PROMPT|INF_EXCLUDE);
  804.          if (Plop || ShutDown || !result)
  805.             {
  806.             if (des)
  807.                FreeUMSConfig(SysUMSAccount, des);
  808.             if (lib)
  809.                FreeUMSConfig(SysUMSAccount, lib);
  810.             if (opt)
  811.                FreeUMSConfig(SysUMSAccount, opt);
  812.             if (cmd)
  813.                FreeUMSConfig(SysUMSAccount, cmd);
  814.  
  815.             return;
  816.             }
  817.  
  818.          strcpy(name, KMS_LC->Session.InputBuffer);
  819.          }
  820.       else
  821.          *name = '\0';
  822.  
  823.       /* Jetzt der Transfer */
  824.  
  825.       PPArg = lib;
  826.       PPArg2 = opt;
  827.       PPArg3 = name;
  828.       StdStringParse(cmd, cmdline, LEN_MAXLINE);
  829.       PPArg = NULL;
  830.       PPArg2 = NULL;
  831.       PPArg3 = NULL;
  832.  
  833.       SystemCall(cmdline);
  834.       }
  835.  
  836.    if (des)
  837.       FreeUMSConfig(SysUMSAccount, des);
  838.    if (lib)
  839.       FreeUMSConfig(SysUMSAccount, lib);
  840.    if (opt)
  841.       FreeUMSConfig(SysUMSAccount, opt);
  842.    if (cmd)
  843.       FreeUMSConfig(SysUMSAccount, cmd);
  844.    }
  845.  
  846. ///
  847.  
  848. /********************************
  849.  * XPRSend                      *
  850.  ********************************
  851.  * I: ---                       *
  852.  * O: Abbruch/Fehler: FALSE     *
  853.  ********************************/
  854.  
  855. /// "XPRSend"
  856.  
  857. BOOL XPRSend(VOID)
  858.    {
  859.    TEXT cmdline[LEN_MAXLINE+1];
  860.    TEXT frompath[LEN_DOSPATH+1];
  861.    TEXT fpaths[LEN_MAXLINE+1];
  862.    TEXT cfgstring[20];
  863.    STRPTR des, lib, opt, cmd, lst;
  864.    UBYTE prot = 0;
  865.    FILE *logfile = NULL;
  866.    BOOL success = FALSE;
  867.    UWORD maxflen = 0;
  868.    LONG sysres = 0;
  869.  
  870.    prot = ProtSelect(TRUE);
  871.    if (!prot)
  872.       return FALSE; /* User-Abbruch */
  873.  
  874.    sprintf(cfgstring, "KMS.xprdescrip%d", prot);
  875.    des = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  876.    sprintf(cfgstring, "KMS.xprlibrary%d", prot);
  877.    lib = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  878.    sprintf(cfgstring, "KMS.xproptions%d", prot);
  879.    opt = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  880.    strcpy(cfgstring, "KMS.xprcmdsend");
  881.    cmd = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  882.    strcpy(cfgstring, "KMS.xprcmdsendlist");
  883.    lst = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  884.  
  885.    if (!des || !lib || !opt || !cmd)
  886.       SystemError("XPRSend", "Prot-Config");
  887.    else
  888.       {
  889.       if (des[strlen(des)-1] == '@')
  890.          {
  891.          /* Batch-Transfer: Alle Dateien aus T:FILES.KMS */
  892.  
  893.          if (!lst || !strlen(lst))
  894.             {
  895.             /* Alle Dateien in Kommandozeile auflisten */
  896.  
  897.             /* Erstes Parsing ohne Dateinamen, um festzustellen, wieviel Platz 
  898.                fuer die Dateipfade uebrig ist */
  899.  
  900.             PPArg = lib;
  901.             PPArg2 = opt;
  902.             StdStringParse(cmd, cmdline, LEN_MAXLINE);
  903.             PPArg = NULL;
  904.             PPArg2 = NULL;
  905.             maxflen = sizeof(cmdline) - strlen(cmdline) - 1;
  906.  
  907.             /* Jetzt Dateiliste erstellen */
  908.  
  909.             logfile = fopen("T:FILES.KMS", "r");
  910.             if (logfile)
  911.                {
  912.                *fpaths = '\0';
  913.  
  914.                while(fgets(frompath, LEN_DOSPATH, logfile))
  915.                   {
  916.                   frompath[strlen(frompath)-1] = '\0';
  917.  
  918.                   if (strlen(fpaths) + 1 + strlen(frompath) <= maxflen)
  919.                      {
  920.                      strcat(fpaths, frompath);
  921.                      strcat(fpaths, " ");
  922.                      }
  923.                   else
  924.                      {
  925.                      /* Zweites Parsing mit Dateiliste */
  926.  
  927.                      PPArg = lib;
  928.                      PPArg2 = opt;
  929.                      PPArg3 = fpaths;
  930.                      StdStringParse(cmd, cmdline, LEN_MAXLINE);
  931.                      PPArg = NULL;
  932.                      PPArg2 = NULL;
  933.                      PPArg3 = NULL;
  934.  
  935.                      /* Kommandoaufruf */
  936.  
  937.                      sysres = SystemCall(cmdline);
  938.  
  939.                      /* Dateiliste mit zuletzt gelesenenem Pfad initialisieren */
  940.  
  941.                      strcpy(fpaths, frompath);
  942.                      strcat(fpaths, " ");
  943.                      }
  944.                   }
  945.  
  946.                /* Nochmal ein Parsing+Aufruf mit übrigen Dateien */
  947.  
  948.                if (!sysres && strlen(fpaths))
  949.                   {
  950.                   PPArg = lib;
  951.                   PPArg2 = opt;
  952.                   PPArg3 = fpaths;
  953.                   StdStringParse(cmd, cmdline, LEN_MAXLINE);
  954.                   PPArg = NULL;
  955.                   PPArg2 = NULL;
  956.                   PPArg3 = NULL;
  957.  
  958.                   sysres = SystemCall(cmdline);
  959.                   }
  960.  
  961.                fclose(logfile);
  962.  
  963.                if (!sysres)
  964.                   success = TRUE;
  965.                else
  966.                   success = FALSE;
  967.                }
  968.             else
  969.                SystemError("XPRSend", "ListRead");
  970.             }
  971.          else
  972.             {
  973.             /* Dateien werden in Listendatei an Sendekommando übergeben */
  974.  
  975.             if (!Copy("T:FILES.KMS", lst, FALSE))
  976.                {
  977.                SystemError("XPRSend", "Copy <xprcmdsendlist>");
  978.  
  979.                success = FALSE;
  980.                }
  981.             else
  982.                {
  983.                PPArg = lib;
  984.                PPArg2 = opt;
  985.                PPArg3 = lst;
  986.                StdStringParse(cmd, cmdline, LEN_MAXLINE);
  987.                PPArg = NULL;
  988.                PPArg2 = NULL;
  989.                PPArg3 = NULL;
  990.  
  991.                /* Kommandoaufruf */
  992.  
  993.                sysres = SystemCall(cmdline);
  994.  
  995.                if (!sysres)
  996.                   success = TRUE;
  997.                else
  998.                   success = FALSE;
  999.                
  1000.                DeleteFile(lst);
  1001.                }
  1002.             }
  1003.          }
  1004.       else
  1005.          {
  1006.          /* Single-Transfer: Alle Dateien aus T:FILES.KMS einzeln */
  1007.  
  1008.          logfile = fopen("T:FILES.KMS", "r");
  1009.          if (logfile)
  1010.             {
  1011.             while(fgets(frompath, LEN_DOSPATH, logfile))
  1012.                {
  1013.                frompath[strlen(frompath)-1] = '\0';
  1014.  
  1015.                PPArg = lib;
  1016.                PPArg2 = opt;
  1017.                PPArg3 = frompath;
  1018.                StdStringParse(cmd, cmdline, LEN_MAXLINE);
  1019.                PPArg = NULL;
  1020.                PPArg2 = NULL;
  1021.                PPArg3 = NULL;
  1022.  
  1023.                sysres = SystemCall(cmdline);
  1024.                }
  1025.  
  1026.             fclose(logfile);
  1027.  
  1028.             if (!sysres)
  1029.                success = TRUE;
  1030.             else
  1031.                success = FALSE;
  1032.             }
  1033.          else
  1034.             SystemError("XPRSend", "ListRead");
  1035.          }
  1036.       }
  1037.  
  1038.    if (des)
  1039.       FreeUMSConfig(SysUMSAccount, des);
  1040.    if (lib)
  1041.       FreeUMSConfig(SysUMSAccount, lib);
  1042.    if (opt)
  1043.       FreeUMSConfig(SysUMSAccount, opt);
  1044.    if (cmd)
  1045.       FreeUMSConfig(SysUMSAccount, cmd);
  1046.    if (lst)
  1047.       FreeUMSConfig(SysUMSAccount, lst);
  1048.  
  1049.    return success;
  1050.    }
  1051.  
  1052. ///
  1053.  
  1054. /********************************
  1055.  * Binärfile umsetzen           *
  1056.  ********************************
  1057.  * I: struct AreaNode *target   *
  1058.  * O: ---                       *
  1059.  ********************************/
  1060.  
  1061. /// "MoveBin"
  1062.  
  1063. BOOL MoveBin(UMSMsgNum source, struct AreaNode *target, BOOL sysop)
  1064.    {
  1065.    TEXT frompath[LEN_DOSPATH+1];
  1066.    TEXT topath[LEN_DOSPATH+1];
  1067.    struct AreaNode *current = KMS_LC->Session.CurrentArea;
  1068.    STRPTR arg;
  1069.    TEXT fname[LEN_DOSFILE+1];
  1070.    BOOL error = FALSE;
  1071.  
  1072.    if (!source)
  1073.       return FALSE;
  1074.  
  1075.    /* Zugriff prüfen */
  1076.  
  1077.    if (!(target->AreaData.Type & ATYPE_FILES))
  1078.       {
  1079.       SysMsg(NO_FILE_AREA);
  1080.       return FALSE;
  1081.       }
  1082.  
  1083.    if (!(CheckAccess(target) & AACC_WRITE))
  1084.       {
  1085.       PPArg = KMS_LC->Session.InputBuffer;
  1086.       SysMsg(NO_WRITE_ACCESS);
  1087.       PPArg = NULL;
  1088.       return FALSE;
  1089.       }
  1090.  
  1091.    /* Filename besorgen */
  1092.  
  1093.    UMSReadTags[0].ti_Data = source;
  1094.  
  1095.    if (!ReadUMSMsg(MyUMSAccount, &UMSReadTags[0]))
  1096.       {
  1097.       SystemError("MoveBin", "ReadUMSMsg");
  1098.       FreeUMSMsg(MyUMSAccount, source);
  1099.       return FALSE;
  1100.       }
  1101.  
  1102.    if (!sysop)
  1103.       {
  1104.       if (!(RMsgInfo.msgi_UserStatus & UMSUSTATF_Owner))
  1105.          {
  1106.          SysMsg(MSG_NOT_OWNED);
  1107.          FreeUMSMsg(MyUMSAccount, source);
  1108.          return FALSE;
  1109.          }
  1110.       }
  1111.  
  1112.    *fname = '\0';
  1113.  
  1114.    if (RAttributes)
  1115.       {
  1116.       /* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
  1117.  
  1118.       if (arg = strstr(RAttributes, "KMS_FNAME:"))
  1119.          sscanf(arg, "KMS_FNAME:%30s", fname);
  1120.       }
  1121.  
  1122.    FreeUMSMsg(MyUMSAccount, source);
  1123.  
  1124.    if (*fname)
  1125.       {
  1126.       /* Datei schon vorhanden? */
  1127.  
  1128.       strcpy(topath, target->AreaData.FilePath);
  1129.       if (topath[strlen(topath)-1] != ':' && topath[strlen(topath)-1] != '/')
  1130.          strcat(topath, "/");
  1131.       strcat(topath, fname);
  1132.       if (Exists(topath))
  1133.          {
  1134.          SysMsg(BINARY_EXISTS);
  1135.          return FALSE;
  1136.          }
  1137.  
  1138.       /* Datei umsetzen nach topath */
  1139.  
  1140.       strcpy(frompath, current->AreaData.FilePath);
  1141.       if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
  1142.          strcat(frompath, "/");
  1143.       strcat(frompath, fname);
  1144.  
  1145.       if (!Copy(frompath, topath, TRUE))
  1146.          {
  1147.          SystemError("MoveBin", "Move");
  1148.          error = TRUE;
  1149.          }
  1150.       }
  1151.  
  1152.    if (!error)
  1153.       return CloneMsg(source, target, sysop);
  1154.    else
  1155.       return FALSE;
  1156.    }
  1157.  
  1158. ///
  1159.  
  1160. /********************************
  1161.  * Fensteradresse besorgen      *
  1162.  ********************************
  1163.  * I: ---                       *
  1164.  * O: struct Window *           *
  1165.  ********************************/
  1166.  
  1167. /// "GetWindow"
  1168.  
  1169. struct Window *GetWindow(VOID)
  1170.    {
  1171.    __aligned struct InfoData info;
  1172.  
  1173.    if (DoPkt(((struct FileHandle *)BADDR(KMS_LC->OutHandle))->fh_Type, ACTION_DISK_INFO, MKBADDR(&info), 0, 0, 0, 0))
  1174.       return info.id_VolumeNode;
  1175.  
  1176.    return NULL;
  1177.    }
  1178.  
  1179. ///
  1180.  
  1181. /********************************
  1182.  * Übertragungsprotokoll wählen *
  1183.  ********************************
  1184.  * I: Vorher fragen?            *
  1185.  * O: Protokoll-Nummer          *
  1186.  ********************************/
  1187.  
  1188. /// "ProtSelect"
  1189.  
  1190. UBYTE ProtSelect(BOOL ask)
  1191.    {
  1192.    STRPTR string, temp;
  1193.    TEXT cfgstring[20];
  1194.    TEXT line[80];
  1195.    TEXT tmp[2];
  1196.    ULONG result;
  1197.    UBYTE count = 1;
  1198.  
  1199.    if (ask)
  1200.       {
  1201.       sprintf(cfgstring, "KMS.xprdescrip%d", KMS_LC->Session.CurrentUser->UserData.Protocol);
  1202.       temp = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE);
  1203.    
  1204.       if (temp)
  1205.          {
  1206.          strcpy(line, temp);
  1207.          if (line[strlen(line)-1] == '@')
  1208.             line[strlen(line)-1] = '\0';
  1209.          
  1210.          PPArg2 = line;
  1211.          CmdInput(NULL, PROMPT_CHANGEPROT, KMSBase->YNText, KMSBase->No, 1, INF_PROMPT|INF_UPCASE);
  1212.          PPArg2 = NULL;
  1213.  
  1214.          FreeUMSConfig(SysUMSAccount, temp);
  1215.          
  1216.          if (Plop || ShutDown)
  1217.             return 0;
  1218.          
  1219.          if (*KMS_LC->Session.InputBuffer == KMSBase->YNText[NO])
  1220.             return KMS_LC->Session.CurrentUser->UserData.Protocol;
  1221.          }
  1222.       }
  1223.  
  1224.    SysMsg(PROTSEL_HEAD);
  1225.    sprintf(cfgstring, "KMS.xprdescrip%d", count);
  1226.    while(count < 10 && (string = ReadUMSConfigTags(SysUMSAccount, UMSTAG_CfgName, cfgstring, TAG_DONE)))
  1227.       {
  1228.       sprintf(line, "%1d) %s", count, string);
  1229.       if (line[strlen(line)-1] == '@')
  1230.          line[strlen(line)-1] = '\0';
  1231.  
  1232.       Print(line, 0);
  1233.  
  1234.       FreeUMSConfig(SysUMSAccount, string);
  1235.  
  1236.       sprintf(cfgstring, "KMS.xprdescrip%d", ++count);
  1237.       }
  1238.    
  1239.    Print(NULL, 0);
  1240.  
  1241.    if (KMS_LC->Session.CurrentUser->UserData.Protocol < count)
  1242.       sprintf(tmp, "%1d", KMS_LC->Session.CurrentUser->UserData.Protocol);
  1243.    else
  1244.       strcpy(tmp, "0");
  1245.    result = CmdInput(NULL, PROMPT_PROTSEL, NULL, tmp, 1, INF_PROMPT|INF_NUMERIC);
  1246.    if (Plop || ShutDown)
  1247.       return 0;
  1248.  
  1249.    if (result > 0 && result < count)
  1250.       {
  1251.       KMS_LC->Session.CurrentUser->UserData.Protocol = result;
  1252.       return result;
  1253.       }
  1254.    else
  1255.       return 0;
  1256.    }
  1257.  
  1258. ///
  1259.  
  1260. /*********************************
  1261.  * Anhängendes Binärfile löschen *
  1262.  *********************************
  1263.  * I: Msg-Nummer, Area           *
  1264.  * O: ---                        *
  1265.  *********************************/
  1266.  
  1267. /// "DeleteBinary"
  1268.  
  1269. VOID DeleteBinary(UMSMsgNum msgnum, struct AreaNode *current)
  1270.    {
  1271.    STRPTR arg;
  1272.    TEXT fname[LEN_DOSFILE+1];
  1273.    TEXT frompath[LEN_DOSPATH+1];
  1274.  
  1275.    /* Attributzeile besorgen */
  1276.  
  1277.    if (!ReadUMSMsgTags(MyUMSAccount, UMSTAG_RMsgNum, msgnum,
  1278.                                   UMSTAG_RAttributes, &RAttributes,
  1279.                                   TAG_DONE))
  1280.       {
  1281.       FreeUMSMsg(MyUMSAccount, msgnum);
  1282.  
  1283.       return;
  1284.       }
  1285.  
  1286.    /* Binärfile dran? */
  1287.  
  1288.    if (RAttributes)
  1289.       {
  1290.       /* "KMS_FNAME:abcd... KMS_FSIZE:12345..." */
  1291.  
  1292.       if (arg = strstr(RAttributes, "KMS_FNAME:"))
  1293.          {
  1294.          *fname = '\0';
  1295.          sscanf(arg, "KMS_FNAME:%30s", fname);
  1296.  
  1297.          strcpy(frompath, current->AreaData.FilePath);
  1298.          if (frompath[strlen(frompath)-1] != ':' && frompath[strlen(frompath)-1] != '/')
  1299.             strcat(frompath, "/");
  1300.          strcat(frompath, fname);
  1301.  
  1302.          /* Datei löschen */
  1303.  
  1304.          DeleteFile(frompath);
  1305.          }
  1306.       }
  1307.  
  1308.    FreeUMSMsg(MyUMSAccount, msgnum);
  1309.    }
  1310.  
  1311. ///
  1312.  
  1313. /*********************************
  1314.  * Upload ins Privat-Verzeichnis *
  1315.  *********************************
  1316.  * I: ---                        *
  1317.  * O: ---                        *
  1318.  *********************************/
  1319.  
  1320. /// "BatchUpload"
  1321.  
  1322. VOID BatchUpload(VOID)
  1323.    {
  1324.    TEXT topath[LEN_DOSPATH+1];
  1325.    TEXT sizebuff[LEN_NUMBER+1];
  1326.    LONG quota;
  1327.  
  1328.    strcpy(topath, KMSBase->UserDir);
  1329.    strcat(topath, KMS_LC->Session.CurrentUser->UserData.Name);
  1330.    ConvertSpace(topath);
  1331.  
  1332.    quota = DirWork(topath, "~(#?.KMS)", 0);
  1333.    quota = KMS_LC->Session.CurrentUser->UserData.Quota * 1024L - quota;
  1334.    if (quota > 0 && quota < SIZE_QUOTAWARN)
  1335.       {
  1336.       sprintf(sizebuff, "%ld", quota);
  1337.       PPArg = sizebuff;
  1338.       SysMsg(QUOTA_WARNING);
  1339.       PPArg = NULL;
  1340.       }
  1341.    else if (quota < 0)
  1342.       SysMsg(QUOTA_EXCEEDED);
  1343.    else
  1344.       Upload(UL_PRIV);
  1345.    }
  1346.  
  1347. ///
  1348.  
  1349. /*********************************
  1350.  * Message-Upload                *
  1351.  *********************************
  1352.  * I: ---                        *
  1353.  * O: ---                        *
  1354.  *********************************/
  1355.  
  1356. /// "MsgUpload"
  1357.  
  1358. VOID MsgUpload(VOID)
  1359.    {
  1360.    Upload(UL_MSG);
  1361.    }
  1362.  
  1363. ///
  1364.  
  1365. /*********************************
  1366.  * Filerequester-Download        *
  1367.  *********************************
  1368.  * I: ---                        *
  1369.  * O: Erfolg TRUE/FALSE          *
  1370.  *********************************/
  1371.  
  1372. /// "LocalDownload"
  1373.  
  1374. BOOL LocalDownload(VOID)
  1375.    {
  1376.    struct Window *mywin;
  1377.    TEXT frompath[LEN_DOSPATH+1];
  1378.    TEXT topath[LEN_DOSPATH+1];
  1379.    STRPTR fname;
  1380.    FILE *logfile;
  1381.  
  1382.    logfile = fopen("T:FILES.KMS", "r");
  1383.    if (logfile)
  1384.       {
  1385.       Print(NULL, 0);
  1386.  
  1387.       if (mywin = GetWindow())
  1388.          {
  1389.          if (AslBase = OpenLibrary(AslName, 36))
  1390.             {
  1391.             if (FileRequester = AllocAslRequest(ASL_FileRequest, NULL))
  1392.                {
  1393.                *topath = '\0';
  1394.  
  1395.                if (AslRequestTags(FileRequester, ASL_Hail, "Select Download Directory",
  1396.                                                  ASL_Window, mywin,
  1397.                                                  ASL_ExtFlags1, FIL1F_NOFILES,
  1398.                                                  TAG_DONE))
  1399.                   {
  1400.                   while(fgets(frompath, LEN_DOSPATH, logfile))
  1401.                      {
  1402.                      frompath[strlen(frompath)-1] = '\0';
  1403.                      fname = FilePart(frompath);
  1404.  
  1405.                      Print(frompath, PF_NOLF);
  1406.                      Print("... ", PF_NOLF);
  1407.  
  1408.                      strcpy(topath, FileRequester->rf_Dir);
  1409.                      if (strlen(topath))
  1410.                         if (topath[strlen(topath)-1] != ':')
  1411.                            strcat(topath, "/");
  1412.                      strcat(topath, fname);
  1413.  
  1414.                      if (*topath)
  1415.                         {
  1416.                         /* frompath nach topath kopieren */
  1417.  
  1418.                         if (Copy(frompath, topath, FALSE))
  1419.                            Print(":-)", 0);
  1420.                         else
  1421.                            Print(":-(", 0);
  1422.                         }
  1423.                      }
  1424.                   }
  1425.  
  1426.                FreeFileRequest(FileRequester);
  1427.                }
  1428.  
  1429.             CloseLibrary(AslBase);
  1430.             }
  1431.          }
  1432.  
  1433.       fclose(logfile);
  1434.       }
  1435.    else
  1436.       SystemError("LocalDownload", "Logread");
  1437.    }
  1438.  
  1439. ///
  1440.  
  1441.